package com.lry.basic.juc;

import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

public class TestS {

    public static void main(String[] args) throws InterruptedException {

        Semaphore semaphoreAsync = new Semaphore(5, true);

        for(int i=0;i<6;i++){
            if(i==4){
                semaphoreAsync.release();
            }
            System.out.println(semaphoreAsync.tryAcquire(1, TimeUnit.SECONDS));
        }


        //waiting thread nums
        System.out.println(semaphoreAsync.getQueueLength());

        //还有几个资源可用
        System.out.println(semaphoreAsync.availablePermits());
    }
}
